package com.MRSyc.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.MRSyc.entity.ICStockBill;
import com.MRSyc.entity.ICStockBillVo;
import com.MRSyc.entity.OutboundDocument;
import com.MRSyc.entity.OutboundDocumentEntry;
import com.MRSyc.entity.TUdiCode;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Fxq
 * @since 2021-01-29
 */
public interface ICStockBillMapper extends BaseMapper<ICStockBill> {
	@Select("select t1.FBrNo, FInterID, FTranType, FDate, FBillNo, FUse, FNote, FDCStockID, FSCStockID, FDeptID, FEmpID, FSupplyID, FPosterID, FCheckerID, FFManagerID, FSManagerID, FBillerID, FReturnBillInterID, FSCBillNo, FHookInterID, FVchInterID, FPosted, FCheckSelect, t1.FCurrencyID, FSaleStyle, FAcctID, FROB, FRSCBillNo, t1.FStatus, FUpStockWhenSave, FCancellation, FOrgBillInterID, FBillTypeID, FPOStyle, FMultiCheckLevel1, FMultiCheckLevel2, FMultiCheckLevel3, FMultiCheckLevel4, FMultiCheckLevel5, FMultiCheckLevel6, FMultiCheckDate1, FMultiCheckDate2, FMultiCheckDate3, FMultiCheckDate4, FMultiCheckDate5, FMultiCheckDate6, FCurCheckLevel, FTaskID, FResourceID, FBackFlushed, FWBInterID, FTranStatus, FZPBillInterID, FRelateBrID, FPurposeID, FUUID, FRelateInvoiceID,  FImport, FSystemType, FMarketingStyle, FPayBillID, FCheckDate, FExplanation, FFetchAdd, FFetchDate, FManagerID, FRefType, FSelTranType, FChildren, FHookStatus, FActPriceVchTplID, FPlanPriceVchTplID, FProcID, FActualVchTplID, FPlanVchTplID, FBrID, FVIPCardID, FVIPScore, FHolisticDiscountRate, FPOSName, FWorkShiftId, FCussentAcctID, FZanGuCount, FPOOrdBillNo, FLSSrcInterID, FSettleDate, t1.FManageType, FOrderAffirm, FAutoCreType, FConsignee, FDrpRelateTranType, FPrintCount, FPOMode, FInventoryType, FObjectItem, FConfirmStatus, FConfirmMem, FConfirmDate, FConfirmer, FAutoCreatePeriod, FYearPeriod, t1.FPayCondition, FsourceType, FReceiver, FInvoiceStatus, FSendStatus, FEnterpriseID, FBillReviewer, FBillReviewDate, FCod, FReceiveMan, FConsigneeAdd, FISUpLoad, FReceiverMobile, FHeadSelfB0163\n" + 
			",t2.fname,t2.FTaxNum from icstockbill t1 left join t_Organization t2 on t1.fsupplyid=t2.fitemid  ${ew.customSqlSegment}")
	IPage<ICStockBillVo> selectByPage(IPage<ICStockBillVo> ipage,@Param(Constants.WRAPPER)QueryWrapper<ICStockBillVo> queryWrapper);
	@Select("select ISNULL(MAX(cast(FInterID as int)),0)+1 from ICStockBill ")
	int findMaxFInterID();
	
	@Select("select t1.FStatus,t1.FBillNo,t4.FName as fsupname,t4.FTaxNum,t4.fnumber as FSupNumber,t4.faddress,t4.f_103 FSupAddCode,t1.fdate,t3.FAlias FShortNumber,t3.FName,t3.FNumber from icstockbill t1 left outer join ICStockBillEntry t2 on t1.FInterID=t2.FInterID inner join t_icitem t3 on t2.FItemID=t3.FItemID\n" + 
			"   inner join t_Organization t4 on t1.FSupplyID=t4.FItemID  ${ew.customSqlSegment}")
    IPage<OutboundDocument> selectOutList(IPage<OutboundDocument> ipage,@Param(Constants.WRAPPER)QueryWrapper<OutboundDocument> queryWrapper);
	
	@Select("select DISTINCT t1.finterid from icstockbill t1 left join ICStockBillEntry t2 on t1.FInterID=t2.FInterID inner join t_item t3 on t2.FItemID=t3.FItemID\n" + 
			"   inner join t_Organization t4 on t1.FSupplyID=t4.FItemID  ${ew.customSqlSegment}")
	List<ICStockBill> selectICStockBillList(@Param(Constants.WRAPPER)QueryWrapper<OutboundDocument> queryWrapper);

	@Select("select t1.fdate,t1.FStatus,t1.FBillNo,t4.FName as fsupname,t4.FPhone,t4.FContact,t4.FTaxNum,t4.fnumber as FSupNumber,t4.faddress,t4.f_103 FSupAddCode,t1.fdate,t6.FMobilePhone as phoneNOOfSalesPerson,t6.fname as FSalesPerson from icstockbill t1   \n" + 
			"   inner join t_Organization t4 on t1.FSupplyID=t4.FItemID left join t_item t5 on t1.fempid=t5.fitemid left join t_emp t6 on t5.fitemid=t6.fitemid  where t1.finterid=#{finterid}")
	OutboundDocument selectByFInterid(int finterid);
	
	@Select("  select FBatchNo as batchNumber,FEntryID as entryNumber,t4.FAlias as materialNumber,t1.FConsignPrice as price,t1.FQty as quantity\n" + 
			"   ,t3.FShortNumber salesUnitCode,t3.FName salesUnitDesc from ICStockBillEntry t1 left join\n" + 
			"    t_item t2 on t1.FItemID=t2.FItemID left join t_item t3 on t1.FUnitID=t3.FItemID left join t_icitem t4 on t2.fitemid=t4.fitemid where FInterID=#{finterid}")
	List<OutboundDocumentEntry> getDocumentEntrys(int finterid);
	
	@Select("select * from t_udi_Code where finterid=#{finterid} and fmaterialNumber=#{fmaterialNumber}")
	List<TUdiCode> getUdiCodes(int finterid,String fmaterialNumber);
	
	@Select("select ISNULL(MAX(id),0)+1 from t_out_result")
	int getMaxId();
}
